package com.edu.web.controller;

import com.edu.control.deploy.sync.DeployStorageRedis;
import com.edu.model.DeployParams;
import com.edu.model.Response;
import com.edu.service.DeployService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class DeployController {

    @Resource
    private DeployService deployService;

    @PostMapping("deploy")
    public Object deploy(DeployParams deployParams) {
        Response deploy = deployService.deploy(deployParams);
        return deploy;
    }

    @PostMapping("testDeploy")
    public Object testDeploy(String eventId, Integer operate) {
        DeployParams deployParams = new DeployParams();
        deployParams.setEventId(eventId);
        deployParams.setOperate(operate);
        Response deploy = deployService.deploy(deployParams);
        return deploy;
    }

    @GetMapping("queryDeployStatus")
    public Object queryDeployStatus(Integer eventId) {
        return DeployStorageRedis.get("event-" + eventId);
    }
}
